﻿Imports System.IO
Imports System.IO.File
Public Class frmAlarmSet
    Delegate Sub AddRecvToText(ByVal strName As String)
    Protected Sub AlarmInfoToTextBox(ByVal s As String)
        If (Alarminfo.InvokeRequired) Then
            Dim cb As AddRecvToText = New AddRecvToText(AddressOf AlarmInfoToTextBox)
            Invoke(cb, s)
        Else
            Alarminfo.AppendText(s + vbCrLf)
        End If
    End Sub
    Private Sub frmAlarmSet_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim alarmstring As String = ""
        Alarminfo.Text = ""
        For i As Integer = 0 To NumberOfAlarmArray - 1
            If myalarm(i).AlarmID <> "" Then
                alarmstring = "编号：" & myalarm(i).AlarmID & "：" & myalarm(i).AlarmInfo & "。" & vbCrLf & "处理办法：" & myalarm(i).Alarmprocess
                AlarmInfoToTextBox(alarmstring)
            End If
        Next

    End Sub

    Private Sub SerchAlarmNOButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SerchAlarmNOButton.Click
        TextBox2.Text = myalarm(TextBox1.Text - 1).AlarmInfo
        TextBox3.Text = myalarm(TextBox1.Text - 1).Alarmprocess
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            GoTo over
        End If
        Dim filepath = My.Application.Info.DirectoryPath & "\Tool\"
        Dim AlarmSetfile_num As Integer = FreeFile()
        '     Dim alarmset As AlarmSetting
        Dim Openalarmsetting As Boolean = Exists(filepath & "alarmsetting.txt")
        If Openalarmsetting = True Then
            '    Kill(filepath & "alarmsetting.txt")
        End If

        FileOpen(AlarmSetfile_num, filepath & "alarmsetting.txt", OpenMode.Random, OpenAccess.Default, OpenShare.Default, 1000)
        myalarm(TextBox1.Text - 1).AlarmID = TextBox1.Text
        myalarm(TextBox1.Text - 1).AlarmInfo = TextBox2.Text
        myalarm(TextBox1.Text - 1).Alarmprocess = TextBox3.Text
        For i As Integer = 0 To 49

            FilePut(AlarmSetfile_num, myalarm(i))
        Next
        FileClose(AlarmSetfile_num)
        MsgBox("修改成功！")
over:
    End Sub
End Class